import GET from '@/interfaces/ajax'

let Get = GET.Get
const Ad = {
    
    namespaced: true,
    state() { 
        return {
            // ajax返回数据初始值
            getDvertInfo: {data: []}
        }
    },
    actions: { 
        async getAd({ commit }) {
            let ret = await Get(config.interface.getAdSwiper + '?siteMark=wap_index&ts')
            // 用正则将'var adList = '截取掉， 最后用JSON.parse将服务器返回的JSON字符串转换为对象
            ret = JSON.parse(ret.replace(/^var\s+adList(?:\s+)?=(?:\s+)?/, ''))
            // ret等同于下面的getDvertInfo
            commit('setGetDvertInfo', ret)
        }     
    },
    getters: {

    },
    mutations: {
        setGetDvertInfo(state, getDvertInfo) {
            state.getDvertInfo = getDvertInfo
        }
    },
    modules: {
        
    }
}

export default Ad